package com.ftqh.tutorial.security.oauth2.provider.client.enums;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2016/12/29
 * \* Time: 17:32
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
@Converter
public class RefreshTokenValidityConverter implements AttributeConverter<RefreshTokenValidity, Integer> {
    @Override
    public Integer convertToDatabaseColumn(RefreshTokenValidity value) {
        if ( value == null ) {
            return null;
        }
        return value.getSeconds();
    }

    @Override
    public RefreshTokenValidity convertToEntityAttribute(Integer value) {
        if ( value == null ) {
            return null;
        }
        return RefreshTokenValidity.fromSeconds( value );
    }
}
